Skip to content

fix: offload message deletion with raw api call#95

Merged
toto04 merged 2 commits intomainfrom
fix-delay
Apr 11, 2026
Merged

fix: offload message deletion with raw api call#95
toto04 merged 2 commits intomainfrom
fix-delay

Conversation

@toto04
Copy link
Copy Markdown
Contributor

@toto04 toto04 commented Apr 11, 2026

No description provided.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 11, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b69b98ff-0fdc-403f-8489-9a72e00486e6

📥 Commits

Reviewing files that changed from the base of the PR and between 3fc84a7 and 853b51d.

📒 Files selected for processing (1)
  • src/utils/messages.ts
✅ Files skipped from review due to trivial changes (1)
  • src/utils/messages.ts

Walkthrough

Changed ephemeral message handling across commands from awaited to fire-and-forget and updated the ephemeral() utility to accept a simpler PartialMessage, tolerate rejected message promises, and delete messages via modules.shared.api.deleteMessage(...) instead of calling msg.delete().

Changes

Cohort / File(s) Summary
Core utility & types
src/utils/messages.ts, src/utils/types.ts
ephemeral() now accepts PartialMessage, tolerates rejected message promises (resolves to null), and deletes via modules.shared.api.deleteMessage(chat.id, message_id); added PartialMessage type.
Global command error handlers
src/commands/index.ts, src/commands/invite.ts, src/commands/link-admin-dashboard.ts, src/lib/managed-commands/index.ts
Replaced await ephemeral(...) with void ephemeral(...) in early-exit/error paths (fire-and-forget).
Moderation commands
src/commands/moderation/ban.ts, src/commands/moderation/del.ts, src/commands/moderation/kick.ts, src/commands/moderation/mute.ts
Removed awaiting of ephemeral(...) in error/notification branches across ban/tban/unban, delete, kick, mute/tmute/unmute handlers; some early returns now return void ephemeral(...).
Pin command
src/commands/pin.ts
Removed unused logger import; changed all ephemeral replies in pin/unpin handlers to void ephemeral(...).
Misc cleanup
src/utils/users.ts
Removed unused logger import.

Sequence Diagram(s)

sequenceDiagram
  participant Handler as Command Handler
  participant Ephemeral as ephemeral()
  participant Resolver as Message Resolver
  participant API as modules.shared.api

  Handler->>Ephemeral: call ephemeral( context.reply(...) )  (void - fire-and-forget)
  Ephemeral->>Resolver: resolve MaybePromise<PartialMessage> (Promise.resolve(...))
  alt resolution succeeds
    Resolver-->>Ephemeral: PartialMessage { chat.id, message_id }
    Ephemeral->>API: schedule deleteMessage(chat.id, message_id) after timeout
    API-->>Ephemeral: delete result (errors ignored)
  else resolution fails
    Resolver-->>Ephemeral: null
    Ephemeral-->>Handler: return early (no delete scheduled)
  end
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: replacing awaited ephemeral message deletion with raw API calls, reducing blocking behavior across multiple command files.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/commands/index.ts (1)

42-49: ⚠️ Potential issue | 🟠 Major

Fire-and-forget here can cause unobserved promise rejections.

At Line 42 and Line 58, context.reply(...) is passed directly to ephemeral(...) and discarded with void. If context.reply rejects, ephemeral rejects before its internal .catch(() => {}), so the rejection is not handled.

🔧 Proposed hardening in src/utils/messages.ts (single fix for all call sites)
 export async function ephemeral(message: MaybePromise<PartialMessage>, timeout = 20000): Promise<void> {
-  const msg = await Promise.resolve(message)
-  await wait(timeout)
-    .then(() => modules.shared.api.deleteMessage(msg.chat.id, msg.message_id))
-    .catch(() => {})
+  await Promise.resolve(message)
+    .then((msg) => wait(timeout).then(() => modules.shared.api.deleteMessage(msg.chat.id, msg.message_id)))
+    .catch(() => {})
 }

Also applies to: 58-58

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/commands/index.ts` around lines 42 - 49, The fire-and-forget use of
ephemeral(context.reply(fmt(...))) can lead to unobserved promise rejections if
context.reply rejects; change call sites (the uses of ephemeral and
context.reply in this file) to ensure the returned promise is handled—either
await the ephemeral(...) call where possible or append a .catch(...) to it so
rejections are observed. Specifically, update the calls that pass
context.reply(...) directly into ephemeral (referencing the ephemeral function
and context.reply + fmt invocation) so that context.reply failures are caught
before being discarded (e.g., await ephemeral(...) or ephemeral(...).catch(() =>
{/*log or noop*/})).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/utils/messages.ts`:
- Around line 50-54: The ephemeral function can throw before its internal .catch
because await Promise.resolve(message) is outside the promise chain; wrap the
entire body in a try-catch (or move the await inside the .then chain) so any
rejection from resolving message (e.g., context.reply()) is caught and ignored;
specifically update the ephemeral function to catch errors from await
Promise.resolve(message) and from modules.shared.api.deleteMessage(msg.chat.id,
msg.message_id) to prevent unhandled rejections when callers use void
ephemeral(...).

---

Outside diff comments:
In `@src/commands/index.ts`:
- Around line 42-49: The fire-and-forget use of
ephemeral(context.reply(fmt(...))) can lead to unobserved promise rejections if
context.reply rejects; change call sites (the uses of ephemeral and
context.reply in this file) to ensure the returned promise is handled—either
await the ephemeral(...) call where possible or append a .catch(...) to it so
rejections are observed. Specifically, update the calls that pass
context.reply(...) directly into ephemeral (referencing the ephemeral function
and context.reply + fmt invocation) so that context.reply failures are caught
before being discarded (e.g., await ephemeral(...) or ephemeral(...).catch(() =>
{/*log or noop*/})).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d0d03722-9000-4cc9-8f58-89e6319f1725

📥 Commits

Reviewing files that changed from the base of the PR and between eb431ea and 3fc84a7.

📒 Files selected for processing (12)
  • src/commands/index.ts
  • src/commands/invite.ts
  • src/commands/link-admin-dashboard.ts
  • src/commands/moderation/ban.ts
  • src/commands/moderation/del.ts
  • src/commands/moderation/kick.ts
  • src/commands/moderation/mute.ts
  • src/commands/pin.ts
  • src/lib/managed-commands/index.ts
  • src/utils/messages.ts
  • src/utils/types.ts
  • src/utils/users.ts
💤 Files with no reviewable changes (1)
  • src/utils/users.ts

@toto04 toto04 merged commit 4b268f8 into main Apr 11, 2026
2 checks passed
@toto04 toto04 deleted the fix-delay branch April 11, 2026 21:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants